<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script th:src="@{/js/jquery.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <style>

        .main {
            margin: 10% auto;
            display: flex;
            justify-content: center;
            flex-direction: column;
            width: 50%;
            height: 50%;
        }

        .pwd-div {
            width: 50%;
            padding: 10px;
            margin: 0 auto;
        }

        .btn-div,
        #confirm {
            margin: 0 auto;
        }
    </style>
</head>

<body>
<div class="container">
    <div class="main">
        <div class="pwd-div">
            <input type="password" id="password" class="form-control form-control-lg" placeholder="请输入密码">
        </div>
        <div class="btn-div">
            <button type="button" id="confirm" class="btn btn-info btn-lg">确定</button>
        </div>
    </div>
</div>

<script>
    $('#confirm').click(function () {
        let formData = new FormData();
        formData.append("pwd", $("#password").val());

        $.ajax({
            url: '/doLogin',
            type: 'POST',
            data: formData,
            contentType: false, // 不设置内容类型
            processData: false, // 不处理发送的数据
            success: function (response) {
                if("0" == response) {
                    alert("密码错误");
                }
                sessionStorage.setItem("fileSystemToken", response);
                index();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });

    function index() {
        window.location.href = "/console?auth_info=" + sessionStorage.getItem("fileSystemToken");
    }
</script>
</body>

</html>